require("Book")

function UnitTests:testBook()

	local book = Book:new()
	
	local descriptor =
	{
		s = {"Character", "Toto"},
		p = 
		{
			{ v = "isAt", doj = {"Location", "Home"}},
			{ c = "and", v = "isA", doj = {"FunyGuy"} },
		}	
	}
	book:addSentence(Sentence:new(descriptor))

	descriptor =
	{
		s = {"Character", "Titi"},
		p = 
		{
			{ v = "isAt", doj = {"Location", "School"}}
		}
	}
	book:addSentence(Sentence:new(descriptor))
	
	local descriptor2 =
	{
		s = {"Location", "School"},
		p = 
		{
			{ v = "is", doj = {"Nice"}},
		}	
	}
	book:addSentence(Sentence:new(descriptor2))
	
	--print(tostring(book))
	
	---
	
	descriptor =
	{
		s = {"Location", "School"},
		p = 
		{
			{ v = "isNot", doj = {"Nice"}},
		}	
	}
	
	local matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(not matched)
	
	---
	
	descriptor =
	{
		s = {"Character", "Toto"},
		p = 
		{
			{ v = "isA", doj = {"FunyGuy"}},
		}	
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(matched)
	
	---
	
	descriptor =
	{
		s = {"Location", "School"},
		p = 
		{
			{ v = "is", doj = {"Nice"}},
		}	
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ v = "isAt", doj = {"Location", "School"}}
			}
		},
		{
			s = {"Location", "School"},
			p = 
			{
				{ v = "is", doj = {"Nice"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ v = "isAt", doj = {"Location", "School"}}
			}
		},
		{
			s = {"Location", "School"},
			p = 
			{
				{ a = {"not"}, v = "is", doj = {"Ugly"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ a = {"not"}, v = "isAt", doj = {"Location", "Home"}}
			}
		},
		{
			s = {"Location", "School"},
			p = 
			{
				{ v = "is", doj = {"Nice"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ a = {"not"}, v = "isAt", doj = {"Location", "Home"}}
			}
		},
		{
			s = {"Location", "School"},
			p = 
			{
				{ a = {"not"}, v = "is", doj = {"Ugly"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ v = "isAt", doj = {"Location", "School"}}
			}
		},
		{
			s = {"Location", "School"},
			p = 
			{
				{ a = {"not"}, v = "is", doj = {"Nice"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(not matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ a = {"not"}, v = "isAt", doj = {"Location", "School"}}
			}
		},
		{
			s = {"Location", "School"},
			p = 
			{
				{ v = "is", doj = {"Nice"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(not matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ a = {"not"}, v = "isAt", doj = {"Location", "School"}}
			}
		},
		{
			s = {"Location", "School"},
			p = 
			{
				{ a = {"not"}, v = "is", doj = {"Nice"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(not matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ v = "isAt", doj = {"Location", "School"}}
			}
		},
		{
			s = {"Location", "School"},
			p = 
			{
				{ v = "isNot", doj = {"Nice"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(not matched)
	
	---
	
	descriptor =
	{
		{
			s = {"Character", "Titi"},
			p = 
			{
				{ v = "isAt", doj = {"Location", "*titiLocation"}}
			}
		},
		{
			s = {"Location", "@titiLocation"},
			p = 
			{
				{ v = "is", doj = {"Nice"}},
			}
		}		
	}
	
	matched = book:matchSentence(Sentence:new(descriptor))
	
	assert(matched)
	assert(book.matchingVariables.titiLocation == "School")
end